﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Tour.DAL;

namespace Tour.BLL
{
    /// <summary>
    /// Summary description for Per_ActionsRoles
    /// </summary>
    public class TblTourManager : TblTourManagerBase
    {
        public TblTourManager()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static TblTourManager CreateInstant()
        {
            return new TblTourManager();
        }

        public List<TblTourEntity> SelectTblTourBy(int? Id, int? TourTypeId, string TextId, bool? IsPromotion, bool? IsHome, bool? IsHot, bool? IsVisible
                                                   , int? PageSize, int? PageIndex, out int TotalRow, string OrderByEx, string Collate)
        {
            TotalRow = 0;
            List<TblTourEntity> lsresult = new List<TblTourEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter("@TotalRow", TotalRow);
            sp.Direction = System.Data.ParameterDirection.Output;
            ls.Add(sp);
            if (Id.HasValue)
                ls.Add(new SqlParameter("@Id", Id.Value));
            if (TourTypeId.HasValue)
                ls.Add(new SqlParameter("@TourTypeId", TourTypeId.Value));
            if (TextId != "")
                ls.Add(new SqlParameter("@TextId", TextId));
            if (IsPromotion.HasValue)
                ls.Add(new SqlParameter("@IsPromotion", IsPromotion.Value));
            if (IsHome.HasValue)
                ls.Add(new SqlParameter("@IsHome", IsHome.Value));
            if (IsHot.HasValue)
                ls.Add(new SqlParameter("@IsHot", IsHot.Value));
            if (IsVisible.HasValue)
                ls.Add(new SqlParameter("@IsVisible", IsVisible.Value));
            if (PageSize.HasValue && PageIndex.HasValue)
            {
                ls.Add(new SqlParameter("@PageSize", PageSize.Value));
                ls.Add(new SqlParameter("@PageIndex", PageIndex.Value));
            }
            if (!OrderByEx.Equals(string.Empty) && !Collate.Equals(string.Empty))
            {
                ls.Add(new SqlParameter("@OrderByEx", OrderByEx));
                ls.Add(new SqlParameter("@Collate", Collate));
            }
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourBy", sqlparam);
            TotalRow = int.Parse(sqlparam[0].Value.ToString());
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblTourEntity(dt.Rows[i]));
            return lsresult;
        }
        public List<TblTourEntity> SelectTblTourBy(int? Id, int? TourTypeId, string TextId, bool? IsPromotion, bool? IsHome, bool? IsHot, bool? IsVisible
                                                   , string OrderByEx, string Collate)
        {
            int TotalRow = 0;
            return SelectTblTourBy(Id, TourTypeId, TextId, IsPromotion, IsHome, IsHot, IsVisible, null, null, out TotalRow, OrderByEx, Collate);
        }
        public void SortTblTour(int TourTypeId)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@TourTypeId", TourTypeId));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SortTblTour", sqlparam);
        }
        public List<TblTourEntity> SelectTblTourBy(int? Id, int? TourTypeId, string TourTypeTextId, string TextId, bool? IsPromotion, bool? IsHome, bool? IsHot, bool? IsVisible
                                                   , int? PageSize, int? PageIndex, out int TotalRow, string OrderByEx, string Collate)
        {
            TotalRow = 0;
            List<TblTourEntity> lsresult = new List<TblTourEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter("@TotalRow", TotalRow);
            sp.Direction = System.Data.ParameterDirection.Output;
            ls.Add(sp);
            if (Id.HasValue)
                ls.Add(new SqlParameter("@Id", Id.Value));
            if (TourTypeId.HasValue)
                ls.Add(new SqlParameter("@TourTypeId", TourTypeId.Value));
            if (TextId != "")
                ls.Add(new SqlParameter("@TextId", TextId));
            if (TourTypeTextId != "")
                ls.Add(new SqlParameter("@TourTypeTextId", TourTypeTextId));
            if (IsPromotion.HasValue)
                ls.Add(new SqlParameter("@IsPromotion", IsPromotion.Value));
            if (IsHome.HasValue)
                ls.Add(new SqlParameter("@IsHome", IsHome.Value));
            if (IsHot.HasValue)
                ls.Add(new SqlParameter("@IsHot", IsHot.Value));
            if (IsVisible.HasValue)
                ls.Add(new SqlParameter("@IsVisible", IsVisible.Value));
            if (PageSize.HasValue && PageIndex.HasValue)
            {
                ls.Add(new SqlParameter("@PageSize", PageSize.Value));
                ls.Add(new SqlParameter("@PageIndex", PageIndex.Value));
            }
            if (!OrderByEx.Equals(string.Empty) && !Collate.Equals(string.Empty))
            {
                ls.Add(new SqlParameter("@OrderByEx", OrderByEx));
                ls.Add(new SqlParameter("@Collate", Collate));
            }
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourBy", sqlparam);
            TotalRow = int.Parse(sqlparam[0].Value.ToString());
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblTourEntity(dt.Rows[i]));
            return lsresult;
        }     
        public List<TblTourEntity> tr_SelectTblTourByTourTypeAllChild(int? TourTypeId, string TourTypeTextId, bool? IsPromotion, bool? IsHome, bool? IsHot, bool? IsVisible
                                               , int? PageSize, int? PageIndex, out int TotalRow, string OrderByEx, string Collate)
        {
            TotalRow = 0;
            List<TblTourEntity> lsresult = new List<TblTourEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter("@TotalRow", TotalRow);
            sp.Direction = System.Data.ParameterDirection.Output;
            ls.Add(sp);
            if (TourTypeId.HasValue)
                ls.Add(new SqlParameter("@TourTypeId", TourTypeId.Value));
            if (TourTypeTextId != "")
                ls.Add(new SqlParameter("@TourTypeTextId", TourTypeTextId));
            if (IsPromotion.HasValue)
                ls.Add(new SqlParameter("@IsPromotion", IsPromotion.Value));
            if (IsHome.HasValue)
                ls.Add(new SqlParameter("@IsHome", IsHome.Value));
            if (IsHot.HasValue)
                ls.Add(new SqlParameter("@IsHot", IsHot.Value));
            if (IsVisible.HasValue)
                ls.Add(new SqlParameter("@IsVisible", IsVisible.Value));
            if (PageSize.HasValue && PageIndex.HasValue)
            {
                ls.Add(new SqlParameter("@PageSize", PageSize.Value));
                ls.Add(new SqlParameter("@PageIndex", PageIndex.Value));
            }
            if (!OrderByEx.Equals(string.Empty) && !Collate.Equals(string.Empty))
            {
                ls.Add(new SqlParameter("@OrderByEx", OrderByEx));
                ls.Add(new SqlParameter("@Collate", Collate));
            }
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourByTourTypeAllChild", sqlparam);
            TotalRow = int.Parse(sqlparam[0].Value.ToString());
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblTourEntity(dt.Rows[i]));
            return lsresult;
        }
    }
}